package com.yuke.cloud.service.uac.utils;

import com.google.common.collect.Lists;
import com.yuke.cloud.common.util.PublicUtil;
import com.yuke.cloud.service.uac.entity.AccMenu;
import com.yuke.cloud.service.uac.entity.AccPermission;
import com.yuke.cloud.service.uac.vo.MenuVo;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.List;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yukemall </br> </p>
 * <p>com.yuke.cloud.service.uac.utils Description TODO </br> </p>
 * @Author wg
 * @Date   2018/11/6 11:06
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BindAuthUtil {

    public static List<MenuVo> getAuthList(List<AccMenu> accMenus, List<AccPermission> accPermissions) {
        List<MenuVo> menuVoList = Lists.newArrayList();
        MenuVo menuVo;
        for (AccMenu uacMenu : accMenus) {
            menuVo = new MenuVo();
            BeanUtils.copyProperties(uacMenu, menuVo);
            menuVo.setDescription("menu");
            menuVoList.add(menuVo);
        }
        if (PublicUtil.isNotEmpty(accPermissions)) {
            for (AccPermission accPermission : accPermissions) {
                menuVo = new MenuVo();
                menuVo.setMenuId(accPermission.getPermissionId());
                menuVo.setMenuName(accPermission.getPermissionName());
                menuVo.setMenuCode(accPermission.getPermissionCode());
                menuVo.setParentId(accPermission.getMenuId());
                menuVo.setUrl(accPermission.getUrl());
                menuVo.setDescription("permission");
                menuVoList.add(menuVo);
            }
        }
        return menuVoList;
    }
}
